package com.aaa.car.controller;

import com.aaa.car.entity.MaintainShop;
import com.aaa.car.service.MaintainShopService;
import com.aaa.common.util.Result;
import com.aaa.common.util.ResultStatus;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (CrsMaintainShop)表控制层
 *
 * @author han qu
 * @since 2021-01-23 17:11:00
 */
@RestController
@RequestMapping("maintainShop")
@ApiOperation("maintainShop控制器")
public class MaintainShopController {
    /**
     * 服务对象
     */
    @Resource
    private MaintainShopService maintainShopService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    @ApiOperation("单个对象查询")
    public Result selectOne(Integer id) {
        return new Result(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.maintainShopService.queryById(id));
    }

    /**
     * 通过实体作为筛选条件查询
     *
     * @return 对象列表
     */
    @PostMapping("queryAll")
    public Result queryAll(Integer pageNo, Integer pageSize, @RequestBody MaintainShop maintainShop) {
        return new Result(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.maintainShopService.queryAll(pageNo, pageSize, maintainShop));
    }

    /**
     * 新增数据
     *
     * @param maintainShop 实例对象
     * @return 实例对象
     */
    @PostMapping("insert")
    public Result insert(@RequestBody MaintainShop maintainShop) {
        return new Result(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.maintainShopService.insert(maintainShop));
    }

    /**
     * 修改数据
     *
     * @param maintainShop 实例对象
     * @return 实例对象
     */
    @PutMapping("update")
    public Result update(@RequestBody MaintainShop maintainShop) {
        return new Result(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.maintainShopService.update(maintainShop));
    }

    /**
     * 通过主键删除数据
     *
     * @param maintainShopId 主键
     * @return 是否成功
     */
    @DeleteMapping("deleteById")
    public Result deleteById(Integer maintainShopId) {
        return new Result(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.maintainShopService.deleteById(maintainShopId));
    }

    /**
     * 验证名字是否可用
     * @param id id
     * @param name 要验证的名字
     * @return 是否可用
     */
    @GetMapping("checkName")
    public Result<Boolean> checkName(@RequestParam("id") String id,@RequestParam("name") String name){
        return new Result<>(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.maintainShopService.checkName(id,name));
    }
}